import fetch from 'node-fetch'
import type { NextApiRequest, NextApiResponse } from 'next';

// 泛型 定义response类型
type Data = {
  name: string
}

// http://localhost:3000/api/hello
export default async (req: NextApiRequest, res: NextApiResponse<Data>) => {
  // if(req.method === 'GET'){
  //   res.status(403);
  //   res.end('internet Error');
  //   return;
  // }

  let result = await fetch(req.query.url, {
    method: req.method,
    body: JSON.stringify(req.body),
    headers: {
      'Content-Type': 'application/json'
    }
  })
  let data = await result.json();
  res.setHeader('Content-Type', 'application/json');
  res.status(200).json(data)
}